/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package gui;

import commodity.Commodity;
import java.util.ArrayList;
import javax.swing.JFrame;
import user.User;

/**
 *
 * @author zyb
 */
public class LoginJFrame extends javax.swing.JFrame {

    public static JFrame frame;
    public static User user = new User();

    /**
     * Creates new form LoginJFrame
     */
    public LoginJFrame() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        LoginLabel1 = new javax.swing.JLabel();
        LoginLabel2 = new javax.swing.JLabel();
        LoginTextField1 = new javax.swing.JTextField();
        LoginTextField2 = new javax.swing.JTextField();
        RegistereButton = new javax.swing.JButton();
        LoginButton = new javax.swing.JButton();
        LoginLabel3 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        LoginLabel1.setText("帐号：");

        LoginLabel2.setText("密码");

        RegistereButton.setText("注册");
        RegistereButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                RegistereButtonActionPerformed(evt);
            }
        });

        LoginButton.setText("登录");
        LoginButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                LoginButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap(62, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(LoginLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(LoginLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(LoginTextField1)
                    .addComponent(LoginTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 202, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(57, 57, 57))
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(105, 105, 105)
                        .addComponent(LoginButton, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(42, 42, 42)
                        .addComponent(RegistereButton, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(82, 82, 82)
                        .addComponent(LoginLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 224, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(49, 49, 49)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(LoginLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(LoginTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(LoginLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(LoginTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(30, 30, 30)
                .addComponent(LoginLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(RegistereButton)
                    .addComponent(LoginButton))
                .addContainerGap(82, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void LoginButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_LoginButtonActionPerformed
        String Account = LoginTextField1.getText();
        String Password = LoginTextField2.getText();
        user.setAccount(Account);
        user.setPassword(Password);
        user = walmart.WalMart.signin(user);
        if (user.getFlag() != 0) {
            frame.setVisible(false);
            frame = new WalmartFrame();
            frame.setTitle("郑玉波-占恒");
            frame.setVisible(true);
        } else {
            LoginLabel3.setText("帐号或密码错误");
        }

    }//GEN-LAST:event_LoginButtonActionPerformed

    private void RegistereButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_RegistereButtonActionPerformed
        frame.setVisible(false);
        frame = new RegistereJFrame();
        frame.setTitle("郑玉波-占恒");
        frame.setVisible(true);
    }//GEN-LAST:event_RegistereButtonActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(LoginJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(LoginJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(LoginJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(LoginJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                frame = new LoginJFrame();
                frame.setTitle("郑玉波-占恒");
                frame.setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton LoginButton;
    private javax.swing.JLabel LoginLabel1;
    private javax.swing.JLabel LoginLabel2;
    private javax.swing.JLabel LoginLabel3;
    private javax.swing.JTextField LoginTextField1;
    private javax.swing.JTextField LoginTextField2;
    private javax.swing.JButton RegistereButton;
    // End of variables declaration//GEN-END:variables

    private class WalmartFrame extends javax.swing.JFrame {

        /**
         * Creates new form WalmartFrame
         */
        public WalmartFrame() {
            initComponents();
            ArrayList<commodity.Commodity> commoditys = walmart.WalMart.readCommodityInformationToFile();
            String[][] playerInfo = new String[commoditys.size()][];
            for (int i = 0; i < commoditys.size(); i++) {
                playerInfo[i] = new String[]{commoditys.get(i).getGoodsName(), "" + commoditys.get(i).getPrice(), "" + commoditys.get(i).getBianHao()};
            }
            String[] rowName = {"商品名", "单价", "商品编号"};
            WalmartTable1.setModel(new javax.swing.table.DefaultTableModel(
                    playerInfo, rowName
            ));
        }

        /**
         * This method is called from within the constructor to initialize the
         * form. WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
         */
        @SuppressWarnings("unchecked")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
        private void initComponents() {

            WalmartLabel1 = new javax.swing.JLabel();
            WalmartTextField1 = new javax.swing.JTextField();
            WalmartLabel2 = new javax.swing.JLabel();
            WalmartTextField2 = new javax.swing.JTextField();
            WalmartButton1 = new javax.swing.JButton();
            jScrollPane1 = new javax.swing.JScrollPane();
            WalmartTable1 = new javax.swing.JTable();
            WalmartButton2 = new javax.swing.JButton();

            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

            WalmartLabel1.setText("购买商品编号：");

            WalmartTextField1.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    WalmartTextField1ActionPerformed(evt);
                }
            });

            WalmartLabel2.setText("购买数量：");

            WalmartButton1.setText("提交");
            WalmartButton1.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    WalmartButton1ActionPerformed(evt);
                }
            });

            WalmartTable1.setModel(new javax.swing.table.DefaultTableModel(
                    new Object[][]{},
                    new String[]{
                        "商品名", "单价", "商品编号"
                    }
            ));
            jScrollPane1.setViewportView(WalmartTable1);

            WalmartButton2.setText("购物车");
            WalmartButton2.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    WalmartButton2ActionPerformed(evt);
                }
            });

            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                    layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(layout.createSequentialGroup()
                                    .addGap(20, 20, 20)
                                    .addComponent(WalmartLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGap(7, 7, 7)
                                    .addComponent(WalmartTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGap(44, 44, 44)
                                    .addComponent(WalmartLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGap(18, 18, 18)
                                    .addComponent(WalmartTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGap(38, 38, 38)
                                    .addComponent(WalmartButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 87, Short.MAX_VALUE)
                                    .addComponent(WalmartButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGap(36, 36, 36))
            );
            layout.setVerticalGroup(
                    layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                    .addGap(44, 44, 44)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                            .addComponent(WalmartLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(WalmartTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(WalmartLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(WalmartTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(WalmartButton1)
                                            .addComponent(WalmartButton2))
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 37, Short.MAX_VALUE)
                                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 396, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addContainerGap())
            );

            pack();
        }// </editor-fold>                        

        private void WalmartTextField1ActionPerformed(java.awt.event.ActionEvent evt) {
            try {
                String a = WalmartTextField1.getText();
                int da = Integer.parseInt(a);
            } catch (java.lang.NumberFormatException e) {
                WalmartTextField1.setText("请输入整数");
            }

        }

        private void WalmartTextFie2d1ActionPerformed(java.awt.event.ActionEvent evt) {
            try {
                String b = WalmartTextField1.getText();
                int db = Integer.parseInt(b);
            } catch (java.lang.NumberFormatException e) {
                WalmartTextField2.setText("请输入整数");
            }

        }

        private void WalmartButton1ActionPerformed(java.awt.event.ActionEvent evt) {
            String a = WalmartTextField1.getText();
            String b = WalmartTextField2.getText();
            int da = Integer.parseInt(a);
            int db = Integer.parseInt(b);
            ArrayList<commodity.Commodity> commoditys = walmart.WalMart.readCommodityInformationToFile();
            if (da > 0 && da <= commoditys.size() && db > 0) {

                Commodity commodity = new Commodity(commoditys.get(da - 1).getGoodsName(), commoditys.get(da - 1).getPrice(), db, commoditys.get(da - 1).getBianHao());
                if (!user.getCart().getCommodities().contains(commodity)) {
                    user.getCart().getCommodities().add(commodity);
                } else {
                    user.getCart().getCommodities().get(user.getCart().getCommodities().indexOf(commodity)).setNumber(db + user.getCart().getCommodities().get(user.getCart().getCommodities().indexOf(commodity)).getNumber());
                }
                ArrayList<User> users = walmart.WalMart.readUserToFile();
                users.set(users.indexOf(user), user);
                walmart.WalMart.writeUserToFile(users);
            }

        }

        private void WalmartButton2ActionPerformed(java.awt.event.ActionEvent evt) {
            LoginJFrame.frame.setVisible(false);
            LoginJFrame.frame = new ShoppingCartJFrame();
            LoginJFrame.frame.setTitle("郑玉波-占恒");
            LoginJFrame.frame.setVisible(true);
        }

        // Variables declaration - do not modify                     
        private javax.swing.JButton WalmartButton1;
        private javax.swing.JButton WalmartButton2;
        private javax.swing.JLabel WalmartLabel1;
        private javax.swing.JLabel WalmartLabel2;
        private javax.swing.JTable WalmartTable1;
        private javax.swing.JTextField WalmartTextField1;
        private javax.swing.JTextField WalmartTextField2;
        private javax.swing.JScrollPane jScrollPane1;
        // End of variables declaration                   
    }

    private class ShoppingCartJFrame extends javax.swing.JFrame {

        /**
         * Creates new form ShoppingCartJFrame
         */
        public ShoppingCartJFrame() {
            initComponents();
            String[][] playerInfo = new String[user.getCart().getCommodities().size()][];
            for (int i = 0; i < user.getCart().getCommodities().size(); i++) {
                playerInfo[i] = new String[]{user.getCart().getCommodities().get(i).getGoodsName(), "" + user.getCart().getCommodities().get(i).getPrice(), "" + user.getCart().getCommodities().get(i).getNumber(), "" + (i + 1)};
            }
            String[] rowName = {"商品名", "单价", "数量", "编号"};
            ShoppingCartTable1.setModel(new javax.swing.table.DefaultTableModel(
                    playerInfo, rowName
            ));
            ShoppingCartLabel1.setText("总价：" + user.getCart().Sum());
            jLabel1.setText("余额：" + user.getMoney());
        }

        /**
         * This method is called from within the constructor to initialize the
         * form. WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
         */
        @SuppressWarnings("unchecked")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
        private void initComponents() {

            jTextField2 = new javax.swing.JTextField();
            jScrollPane1 = new javax.swing.JScrollPane();
            ShoppingCartTable1 = new javax.swing.JTable();
            ShoppingCartButton1 = new javax.swing.JButton();
            ShoppingCartButton2 = new javax.swing.JButton();
            ShoppingCartButton3 = new javax.swing.JButton();
            ShoppingCartLabel1 = new javax.swing.JLabel();
            jLabel2 = new javax.swing.JLabel();
            ShoppingCartTextField1 = new javax.swing.JTextField();
            ShoppingCartButton4 = new javax.swing.JButton();
            ShoppingCartLabel3 = new javax.swing.JLabel();
            jLabel1 = new javax.swing.JLabel();

            jTextField2.setText("jTextField2");

            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

            ShoppingCartTable1.setModel(new javax.swing.table.DefaultTableModel(
                    new Object[][]{},
                    new String[]{
                        "商品名", "单价", "数量", "编号"
                    }
            ));
            jScrollPane1.setViewportView(ShoppingCartTable1);

            ShoppingCartButton1.setText("前往商城");
            ShoppingCartButton1.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    ShoppingCartButton1ActionPerformed(evt);
                }
            });

            ShoppingCartButton2.setText("结算");
            ShoppingCartButton2.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    ShoppingCartButton2ActionPerformed(evt);
                }
            });

            ShoppingCartButton3.setText("充值");
            ShoppingCartButton3.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    ShoppingCartButton3ActionPerformed(evt);
                }
            });

            ShoppingCartLabel1.setText("总价：");

            jLabel2.setText("删除商品编号：");

            ShoppingCartTextField1.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    ShoppingCartTextField1ActionPerformed(evt);
                }
            });

            ShoppingCartButton4.setText("删除");
            ShoppingCartButton4.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    ShoppingCartButton4ActionPerformed(evt);
                }
            });

            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                    layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                    .addContainerGap()
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addGroup(layout.createSequentialGroup()
                                                    .addComponent(ShoppingCartButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                    .addGap(27, 27, 27)
                                                    .addComponent(ShoppingCartButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                    .addGap(18, 18, 18)
                                                    .addComponent(ShoppingCartButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                    .addGap(34, 34, 34)
                                                    .addComponent(jLabel2)
                                                    .addGap(1, 1, 1)
                                                    .addComponent(ShoppingCartTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                                    .addComponent(ShoppingCartButton4, javax.swing.GroupLayout.DEFAULT_SIZE, 72, Short.MAX_VALUE)
                                                    .addContainerGap())
                                            .addGroup(layout.createSequentialGroup()
                                                    .addComponent(ShoppingCartLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                    .addGap(62, 62, 62)
                                                    .addComponent(ShoppingCartLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 196, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                    .addGap(40, 40, 40))))
                            .addComponent(jScrollPane1)
            );
            layout.setVerticalGroup(
                    layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                    .addContainerGap()
                                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 302, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                            .addComponent(ShoppingCartLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                            .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                            .addComponent(ShoppingCartLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 34, Short.MAX_VALUE))
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 12, Short.MAX_VALUE)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                            .addComponent(ShoppingCartButton1)
                                            .addComponent(ShoppingCartButton2)
                                            .addComponent(ShoppingCartButton3)
                                            .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                            .addComponent(ShoppingCartTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(ShoppingCartButton4))
                                    .addGap(50, 50, 50))
            );

            pack();
        }// </editor-fold>                        

        private void ShoppingCartButton1ActionPerformed(java.awt.event.ActionEvent evt) {
            frame.setVisible(false);
            frame = new WalmartFrame();
            frame.setTitle("郑玉波-占恒");
            frame.setVisible(true);
        }

        private void ShoppingCartButton2ActionPerformed(java.awt.event.ActionEvent evt) {
            if (user.getMoney() >= user.getCart().Sum()) {
                user.setMoney(user.getMoney() - user.getCart().Sum());
                ArrayList<User> users = walmart.WalMart.readUserToFile();
                user.getCart().getCommodities().clear();
                users.set(users.indexOf(user), user);
                walmart.WalMart.writeUserToFile(users);
                frame.setVisible(false);
                frame = new ShoppingCartJFrame();
                frame.setTitle("郑玉波-占恒");
                frame.setVisible(true);

            } else {
                ShoppingCartLabel3.setText("您的余额不够");
            }
        }

        private void ShoppingCartButton3ActionPerformed(java.awt.event.ActionEvent evt) {
            frame.setVisible(false);
            frame = new RunJFrame();
            frame.setTitle("郑玉波-占恒");
            frame.setVisible(true);
        }

        private void ShoppingCartButton4ActionPerformed(java.awt.event.ActionEvent evt) {
            String a = ShoppingCartTextField1.getText();
            int da = Integer.parseInt(a);
            if (da > 0 && da <= user.getCart().getCommodities().size()) {
                user.getCart().getCommodities().remove(da-1);
            }
            ArrayList<User> users = walmart.WalMart.readUserToFile();
            users.set(users.indexOf(user), user);
            walmart.WalMart.writeUserToFile(users);
            frame.setVisible(false);
            frame = new ShoppingCartJFrame();
            frame.setTitle("郑玉波-占恒");
            frame.setVisible(true);
        }

        private void ShoppingCartTextField1ActionPerformed(java.awt.event.ActionEvent evt) {
            // TODO add your handling code here:
        }

        // Variables declaration - do not modify                     
        private javax.swing.JButton ShoppingCartButton1;
        private javax.swing.JButton ShoppingCartButton2;
        private javax.swing.JButton ShoppingCartButton3;
        private javax.swing.JButton ShoppingCartButton4;
        private javax.swing.JLabel ShoppingCartLabel1;
        private javax.swing.JLabel ShoppingCartLabel3;
        private javax.swing.JTable ShoppingCartTable1;
        private javax.swing.JTextField ShoppingCartTextField1;
        private javax.swing.JLabel jLabel1;
        private javax.swing.JLabel jLabel2;
        private javax.swing.JScrollPane jScrollPane1;
        private javax.swing.JTextField jTextField2;
        // End of variables declaration                   

        private class RunJFrame extends javax.swing.JFrame {

            /**
             * Creates new form RunJFrame
             */
            public RunJFrame() {
                initComponents();
            }

            /**
             * This method is called from within the constructor to initialize
             * the form. WARNING: Do NOT modify this code. The content of this
             * method is always regenerated by the Form Editor.
             */
            @SuppressWarnings("unchecked")
            // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
            private void initComponents() {

                jLabel1 = new javax.swing.JLabel();
                jButton1 = new javax.swing.JButton();
                jTextField1 = new javax.swing.JTextField();
                jButton2 = new javax.swing.JButton();
                jLabel2 = new javax.swing.JLabel();

                setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

                jLabel1.setText("充值金额：");

                jButton1.setText("确定");
                jButton1.addActionListener(new java.awt.event.ActionListener() {
                    public void actionPerformed(java.awt.event.ActionEvent evt) {
                        jButton1ActionPerformed(evt);
                    }
                });

                jTextField1.addActionListener(new java.awt.event.ActionListener() {
                    public void actionPerformed(java.awt.event.ActionEvent evt) {
                        jTextField1ActionPerformed(evt);
                    }
                });

                jButton2.setText("取消");
                jButton2.addActionListener(new java.awt.event.ActionListener() {
                    public void actionPerformed(java.awt.event.ActionEvent evt) {
                        jButton2ActionPerformed(evt);
                    }
                });

                javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
                getContentPane().setLayout(layout);
                layout.setHorizontalGroup(
                        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(layout.createSequentialGroup()
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addGroup(layout.createSequentialGroup()
                                                        .addGap(56, 56, 56)
                                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                                                .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                                .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 83, Short.MAX_VALUE))
                                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                                                .addGroup(layout.createSequentialGroup()
                                                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                                        .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 134, javax.swing.GroupLayout.PREFERRED_SIZE))
                                                                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                                        .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                                        .addGap(20, 20, 20))))
                                                .addGroup(layout.createSequentialGroup()
                                                        .addGap(93, 93, 93)
                                                        .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 172, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                        .addContainerGap(115, Short.MAX_VALUE))
                );
                layout.setVerticalGroup(
                        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(layout.createSequentialGroup()
                                        .addGap(84, 84, 84)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addGap(37, 37, 37)
                                        .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 26, Short.MAX_VALUE)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                                .addComponent(jButton1)
                                                .addComponent(jButton2))
                                        .addGap(70, 70, 70))
                );

                pack();
            }// </editor-fold>                        

            private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
                String a = jTextField1.getText();
                double da = Double.parseDouble(a);
                user.setMoney(user.getMoney() + da);
                ArrayList<User> users = walmart.WalMart.readUserToFile();
                users.set(users.indexOf(user), user);
                walmart.WalMart.writeUserToFile(users);
                frame.setVisible(false);
                frame = new ShoppingCartJFrame();
                frame.setTitle("郑玉波-占恒");
                frame.setVisible(true);
            }

            private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
                frame.setVisible(false);
                frame = new ShoppingCartJFrame();
                frame.setTitle("郑玉波-占恒");
                frame.setVisible(true);
            }

            private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {
                try {
                    String a = jTextField1.getText();
                    double da = Double.parseDouble(a);
                } catch (java.lang.NumberFormatException e) {
                    jLabel2.setText("请输入数字");
                    jTextField1.setText("0.0");
                }
            }

            // Variables declaration - do not modify                     
            private javax.swing.JButton jButton1;
            private javax.swing.JButton jButton2;
            private javax.swing.JLabel jLabel1;
            private javax.swing.JLabel jLabel2;
            private javax.swing.JTextField jTextField1;
            // End of variables declaration                   
        }

    }

    private class RegistereJFrame extends javax.swing.JFrame {

        /**
         * Creates new form RegistereJFrame
         */
        public RegistereJFrame() {
            initComponents();
        }

        /**
         * This method is called from within the constructor to initialize the
         * form. WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
         */
        @SuppressWarnings("unchecked")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
        private void initComponents() {

            jLabel1 = new javax.swing.JLabel();
            jLabel2 = new javax.swing.JLabel();
            jLabel3 = new javax.swing.JLabel();
            jLabel4 = new javax.swing.JLabel();
            jTextField1 = new javax.swing.JTextField();
            jTextField2 = new javax.swing.JTextField();
            jTextField3 = new javax.swing.JTextField();
            jButton1 = new javax.swing.JButton();

            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

            jLabel1.setText("注册：");

            jLabel2.setText("姓名：");

            jLabel3.setText("地址：");

            jLabel4.setText("密码：");

            jTextField1.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jTextField1ActionPerformed(evt);
                }
            });

            jTextField2.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jTextField2ActionPerformed(evt);
                }
            });

            jTextField3.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jTextField3ActionPerformed(evt);
                }
            });

            jButton1.setText("确定");
            jButton1.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jButton1ActionPerformed(evt);
                }
            });

            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                    layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addGroup(layout.createSequentialGroup()
                                                    .addGap(48, 48, 48)
                                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                                            .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                            .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                            .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE))
                                                    .addGap(4, 4, 4)
                                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                            .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                                                    .addComponent(jTextField1)
                                                                    .addComponent(jTextField2)
                                                                    .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, 194, javax.swing.GroupLayout.PREFERRED_SIZE))))
                                            .addGroup(layout.createSequentialGroup()
                                                    .addContainerGap()
                                                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                    .addContainerGap(71, Short.MAX_VALUE))
            );
            layout.setVerticalGroup(
                    layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                    .addContainerGap()
                                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGap(18, 18, 18)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                            .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                            .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                            .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 69, Short.MAX_VALUE)
                                    .addComponent(jButton1)
                                    .addGap(62, 62, 62))
            );

            pack();
        }// </editor-fold>                        

        private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {
            // TODO add your handling code here:
        }

        private void jTextField2ActionPerformed(java.awt.event.ActionEvent evt) {
            // TODO add your handling code here:
        }

        private void jTextField3ActionPerformed(java.awt.event.ActionEvent evt) {
            // TODO add your handling code here:
        }

        private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
            String a = jTextField1.getText();
            String b = jTextField2.getText();
            String c = jTextField3.getText();
            user.setName(a);
            user.setAddress(b);
            user.setPassword(c);
            user = walmart.WalMart.registere(user);
            frame.setVisible(false);
            frame = new RunJFrame();
            frame.setTitle("郑玉波-占恒");
            frame.setVisible(true);
        }

        // Variables declaration - do not modify                     
        private javax.swing.JButton jButton1;
        private javax.swing.JLabel jLabel1;
        private javax.swing.JLabel jLabel2;
        private javax.swing.JLabel jLabel3;
        private javax.swing.JLabel jLabel4;
        private javax.swing.JTextField jTextField1;
        private javax.swing.JTextField jTextField2;
        private javax.swing.JTextField jTextField3;
        // End of variables declaration       

        private class RunJFrame extends javax.swing.JFrame {

            /**
             * Creates new form RunJFrame
             */
            public RunJFrame() {
                initComponents();
                jLabel1.setText("您的帐号为：" + user.getAccount());
            }

            /**
             * This method is called from within the constructor to initialize
             * the form. WARNING: Do NOT modify this code. The content of this
             * method is always regenerated by the Form Editor.
             */
            @SuppressWarnings("unchecked")
            // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
            private void initComponents() {

                jLabel1 = new javax.swing.JLabel();
                jButton1 = new javax.swing.JButton();

                setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

                jButton1.setText("确定");
                jButton1.addActionListener(new java.awt.event.ActionListener() {
                    public void actionPerformed(java.awt.event.ActionEvent evt) {
                        jButton1ActionPerformed(evt);
                    }
                });

                javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
                getContentPane().setLayout(layout);
                layout.setHorizontalGroup(
                        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(layout.createSequentialGroup()
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addGroup(layout.createSequentialGroup()
                                                        .addGap(46, 46, 46)
                                                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 302, javax.swing.GroupLayout.PREFERRED_SIZE))
                                                .addGroup(layout.createSequentialGroup()
                                                        .addGap(150, 150, 150)
                                                        .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                        .addContainerGap(52, Short.MAX_VALUE))
                );
                layout.setVerticalGroup(
                        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(layout.createSequentialGroup()
                                        .addGap(35, 35, 35)
                                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 77, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 89, Short.MAX_VALUE)
                                        .addComponent(jButton1)
                                        .addGap(70, 70, 70))
                );

                pack();
            }// </editor-fold>                        

            private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
                frame.setVisible(false);
                frame = new WalmartFrame();
                frame.setTitle("郑玉波-占恒");
                frame.setVisible(true);
            }

            // Variables declaration - do not modify                     
            private javax.swing.JButton jButton1;
            private javax.swing.JLabel jLabel1;
            // End of variables declaration                   
        }

    }

}
